import { createSlice, PayloadAction } from '@reduxjs/toolkit'
import type { SizeType } from "antd/lib/config-provider/SizeContext";

/* themeConfigProp */
export interface ThemeConfigProp {
	primary: string;
	isDark: boolean;
	weakOrGray: string;
	breadcrumb: boolean;
	tabs: boolean;
	footer: boolean;
}

/* GlobalState */
export interface GlobalState {
	name: string;
	token: string;
	userInfo: any;
	assemblySize: SizeType;
	language: string;
	themeConfig: ThemeConfigProp;
}

const initialState: GlobalState = {
  name: "",
  token: "",
  userInfo: "",
  assemblySize: "middle",
  language: "",
  themeConfig: {
    // 默认 primary 主题颜色
    primary: "#1890ff",
    // 深色模式
    isDark: false,
    // 色弱模式(weak) || 灰色模式(gray)
    weakOrGray: "",
    // 面包屑导航
    breadcrumb: false,
    // 标签页
    tabs: true,
    // 页脚
    footer: false
  }
};


export const globalSlice = createSlice({
  name: 'global',
  initialState,
  reducers: {
    setToken: (state, action: PayloadAction<string>) => {
      state.token = action.payload
    },
    setName: (state, action: PayloadAction<string>) => {
      state.name = action.payload
    },
    setAssemblySize: (state, action: PayloadAction<SizeType>) => {
      state.assemblySize = action.payload
    },
    setLanguage: (state, action: PayloadAction<string>) => {
      state.language = action.payload
    },
    setThemeConfig: (state, action: PayloadAction<ThemeConfigProp>) => {
      state.themeConfig = action.payload
    },
    
  },
})

export const { setToken, setName, setAssemblySize, setLanguage, setThemeConfig } = globalSlice.actions

export default globalSlice.reducer